import base64
import requests
from URL import FDU, API


def detect_faces():
    with open(r"D:\zm\人工智能与信息技术\4.1\image\3.jpg", 'rb') as f:
        image_data = base64.b64encode(f.read()).decode()

    response = requests.post(
        FDU,
        data={
            "access_token": API,
            "image": image_data,
            "image_type": "BASE64",
            "face_field": "location",
            "max_face_num": 10
        }
    )
    return response.json()['result']['face_list']


faces = detect_faces()
print(faces)
for i, face in enumerate(faces):
    loc = face['location']
    print(f"人脸{i + 1}: 左{loc['left']}px 上{loc['top']}px 宽{loc['width']}px 高{loc['height']}px")
